﻿using Microsoft.AspNetCore.SignalR.Client;

namespace MyDocuments.Shared
{
    public class RetryPolicy : IRetryPolicy
    {
        public TimeSpan? NextRetryDelay(RetryContext retryContext)
        {
            if (retryContext == null) return TimeSpan.FromSeconds(1);
            if (retryContext.PreviousRetryCount <= 1) return TimeSpan.FromSeconds(retryContext.PreviousRetryCount);
            var delay = retryContext.PreviousRetryCount % 10;
            return TimeSpan.FromSeconds(delay > 1 ? delay : 2);
        }
    }
}
